<template>
  <div>
    <el-breadcrumb>
      <el-breadcrumb-item>员工管理</el-breadcrumb-item>
      <el-breadcrumb-item>更新员工</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form
        :model="updateForm"
        label-width="100px"
        style="margin-top: 20px"
    >
      <el-form-item label="手机号">
        <el-input v-model="updateForm.tel" disabled />
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model="updateForm.gmName" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="updateForm.password" type="password" />
      </el-form-item>
      <el-form-item label="省份ID">
        <el-input v-model="updateForm.provinceId" type="number" />
      </el-form-item>
      <el-form-item label="城市ID">
        <el-input v-model="updateForm.cityId" type="number" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="updateForm.remarks" type="textarea" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitUpdate">提交</el-button>
        <el-button @click="cancelUpdate">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { reactive, ref, inject, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import RemarksDetails from "@/components/RemarksDetails.vue";

const route = useRoute();
const router = useRouter();
const axios = inject("axios");

const updateForm = reactive({
  gmId: "",
  gmName: "",
  gmCode: "",
  password: "",
  provinceId: "",
  cityId: "",
  tel: "",
  remarks: "",
});

const getMemberDetails = async () => {
  const gmId = route.query.gmId; // 修改为 gmId
  const response = await axios.get(`gridMember/getGridMemberDetails?gmId=${gmId}`);
  Object.assign(updateForm, response.data);
};

onMounted(() => {
  getMemberDetails();
});

const submitUpdate = async () => {
  const response = await axios.post("gridMember/updateGridMember", updateForm);
  if (response.data.success) {
    ElMessage.success("更新成功");
    router.push("/index/gridMemberList");
  } else {
    ElMessage.error("更新失败");
  }
};

const cancelUpdate = () => {
  router.push("/index/gridMemberList");
};
</script>

<style scoped>
.pagination {
  display: flex;
  justify-content: center;
}
</style>